#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
应用配置管理
"""

import os
from dataclasses import dataclass
from typing import Dict, List, Optional
from pathlib import Path

@dataclass
class DatabaseConfig:
    """数据库配置"""
    host: str = "trino.aihuishou.com"
    port: int = 9090
    user: str = "u_algorithm"
    database: str = "hive/default"
    connection_string: str = "presto://u_algorithm@trino.aihuishou.com:9090/hive/default"

@dataclass
class ProcessingConfig:
    """处理配置"""
    max_workers: int = 4
    timeout: int = 120
    chunk_size: int = 1000
    cache_ttl: int = 3600

@dataclass
class UIConfig:
    """界面配置"""
    page_title: str = "价格策略分析平台 v2.0"
    page_icon: str = "📊"
    layout: str = "wide"
    theme: str = "light"

class AppConfig:
    """应用配置主类"""
    
    def __init__(self):
        self.database = DatabaseConfig()
        self.processing = ProcessingConfig()
        self.ui = UIConfig()
        
        # 产品配置
        self._products = {
            "手机": {
                "苹果": [
                    '苹果 iPhone 12', '苹果 iPhone 13', '苹果 iPhone 14', '苹果 iPhone 15', '苹果 iPhone 16',
                    '苹果 iPhone 12 Pro', '苹果 iPhone 13 Pro', '苹果 iPhone 14 Pro', '苹果 iPhone 15 Pro', '苹果 iPhone 16 Pro',
                    '苹果 iPhone 12 Pro Max', '苹果 iPhone 13 Pro Max', '苹果 iPhone 14 Pro Max', '苹果 iPhone 15 Pro Max', '苹果 iPhone 16 Pro Max',
                ],
                "安卓": [
                    'Redmi K60', '小米 13', '华为 Mate 60 Pro', '华为 Mate 40 Pro (5G版)', '华为 P40 Pro', '华为 Mate 30 Pro (5G版)', '小米 14',
                    '华为 Pocket 2', '小米 13 Ultra', '一加 Ace 2', 'Redmi K70', '小米 13 Pro', '华为 Mate 50 Pro', '华为 Mate 60', '华为 Mate 50',
                    '三星 Galaxy S23 Ultra', '华为 Mate 60 Pro+', '华为 Mate X5', '小米 15', '小米 14 Pro', 'Redmi Note 13 Pro', 'Redmi K70 (至尊版)',
                    'vivo X100', '一加 Ace 3', '小米 MIX Flip', '华为 Mate 60 RS 非凡大师', 'vivo X100 Ultra', '一加 12', 'REDMI K80', '小米 15 Pro',
                    'vivo X100 Pro', 'OPPO Find X7 Ultra', '华为 Pura 70 Pro', '荣耀 Magic6 Pro', 'OPPO Find X8', '一加 13', '一加 Ace 3 Pro',
                    '华为 Pura 70', 'vivo X Fold 3', '三星 Galaxy S23', '一加 Ace 5','华为 Pura 70 Ultra', '三星 Galaxy S24 Ultra', '小米 14 Ultra',
                    '华为 Pura 70 北斗卫星消息版', '华为 Mate 70', 'vivo X200 Pro', '华为 Mate X5 典藏版', '荣耀 Magic V3', 'vivo X Fold 3 Pro', '小米 MIX Fold 4',
                    '华为 Pura 70 Pro+', '三星 Galaxy Z Flip5 (5G版)', '华为 Mate 70 Pro+', '荣耀 Magic7 Pro', '荣耀 Magic7', 'OPPO Find X8 Pro',
                    '华为 Mate X3', 'vivo X200', 'vivo X200 Pro mini', '华为 nova 13', '小米 15 Ultra', '华为 Mate X6', 'OPPO Find N3', '三星 Galaxy Z Fold5 (5G版)',
                    '华为 Mate XT 非凡大师', '华为 Mate 70 RS 非凡大师', '三星 Galaxy S25 Ultra', '三星 Galaxy Z Fold6 (5G版)', '三星 W25'
                ],
                "全部": []
            },
            "平板": [
                'iPad 9代', 'iPad Air5', 'iPad mini6', 'iPad Pro 4代 11英寸', 'iPad 10代', 'iPad 6代', 'iPad 8代', 'iPad Air2', 'iPad mini5', 'iPad Air (M2) 11英寸',
                'iPad Air3', 'iPad mini4', 'iPad Air4', 'iPad 7代', 'iPad Pro 2代 11英寸', 'iPad 5代', 'iPad Pro 5代 12.9英寸', 'iPad Pro (M4) 11英寸', 'iPad mini7',
                'iPad Pro 3代 11英寸', 'iPad Pro 1代 11英寸'
            ],
            "智能手表": [
                'Apple Watch Series 7', 'Apple Watch Series 9', 'Apple Watch SE', 'Apple Watch Series 8', 'Apple Watch Series 6', 'Apple Watch Series 10',
                'Apple Watch Series 5', 'Apple Watch SE 2', 'Apple Watch Series 3', 'Apple Watch Ultra', 'Apple Watch Ultra 2',
            ],
            "耳机": [
                '苹果 AirPods Pro 2', '苹果 AirPods 4',
                '华为 FreeBuds Pro 3', '小米 Buds 4',
                '索尼 WF-1000XM5'
            ],
            "笔记本": [
                '苹果 MacBook Air', '苹果 MacBook Pro 14', '苹果 MacBook Pro 16',
                '华为 MateBook X Pro', '联想 ThinkPad X1',
                '戴尔 XPS 13', '惠普 Spectre x360'
            ]
        }
        
        # 初始化手机全部产品列表
        self._products["手机"]["全部"] = (
            self._products["手机"]["苹果"] + 
            self._products["手机"]["安卓"]
        )
    
    def get_products(self, category: str, brand: Optional[str] = None) -> List[str]:
        """获取产品列表"""
        if category not in self._products:
            return []
        
        category_products = self._products[category]
        
        if isinstance(category_products, list):
            return category_products
        elif isinstance(category_products, dict):
            if brand and brand in category_products:
                return category_products[brand]
            else:
                # 返回所有品牌的产品
                all_products = []
                for brand_products in category_products.values():
                    if isinstance(brand_products, list):
                        all_products.extend(brand_products)
                return all_products
        
        return []
    
    def get_categories(self) -> List[str]:
        """获取所有产品类别"""
        return list(self._products.keys())
    
    def get_brands(self, category: str) -> List[str]:
        """获取指定类别的品牌列表"""
        if category not in self._products:
            return []
        
        category_products = self._products[category]
        if isinstance(category_products, dict):
            return list(category_products.keys())
        
        return []